import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';
import 'package:search_people/entrance/route/routes.dart';
import 'package:search_people/global/user/logic.dart';
import 'package:search_people/value/topcolors.dart';

import '../../utils/img_util.dart';
import 'index.dart';
import 'widgets/cell.dart';

class MePage extends StatelessWidget {
  MePage({Key? key}) : super(key: key);
  final controller = Get.put(MeController());
  final state = Get.find<MeController>().state;
  // 主视图
  Widget _buildView() {
    return Stack(
      children: [
        Positioned(
          child: Container(
            margin: EdgeInsets.only(top: 110.r),
            decoration: BoxDecoration(
              color: Colors.white,
              borderRadius: BorderRadius.vertical(
                top: Radius.circular(20.r),
              ),
            ),
          ),
        ),
        ListView(
          children: [
            Container(
              padding: EdgeInsets.symmetric(vertical: 20.r, horizontal: 30.r),
              margin: EdgeInsets.fromLTRB(20.r, 40.r, 20.r, 0),
              height: 100.r,
              decoration: BoxDecoration(
                  color: Colors.white,
                  borderRadius: BorderRadius.circular(50.r),
                  boxShadow: [
                    BoxShadow(
                      color: Colors.green.withAlpha(10),
                      offset: Offset(3, 3),
                    ),
                    BoxShadow(
                      color: Colors.green.withAlpha(5),
                      offset: Offset(10, 10),
                    )
                  ]),
              alignment: Alignment.centerLeft,
              child: Row(
                children: [
                  InkWell(
                    // onTap: controller.uploadAvater,
                    child: Container(
                        decoration: BoxDecoration(
                            border: Border.all(color: Colors.white, width: 0),
                            borderRadius:
                                const BorderRadius.all(Radius.circular(180))),
                        width: 62,
                        height: 62,
                        child: Obx(
                          () => loadAvater(
                              size: 62,
                              url: UserController()
                                  .state
                                  .userObs
                                  .value
                                  .headImgUrl),
                        )),
                  ),
                  SizedBox(
                    width: 10.r,
                  ),
                  Column(
                    crossAxisAlignment: CrossAxisAlignment.start,
                    mainAxisAlignment: MainAxisAlignment.center,
                    children: [
                      GestureDetector(
                        onTap: () {
                          if (UserController().isLogin) {
                            return;
                          }
                          Get.toNamed(RouterPath.login);
                        },
                        child: Obx(
                          () => Text(
                            UserController().isLoginObs.value
                                ? (UserController()
                                        .state
                                        .userObs
                                        .value
                                        .userName ??
                                    '')
                                : '登录/注册',
                            style: TextStyle(
                                color: TopColors.black_33,
                                fontSize: 18.sp,
                                fontWeight: FontWeight.w600),
                          ),
                        ),
                      ),
                      // Text(
                      //  'xx会员',
                      //   style: TextStyle(
                      //     color: TopColors.black_33,
                      //     fontSize: 12.sp,
                      //   ),
                      // )
                    ],
                  ),
                ],
              ),
            ),
            SizedBox(
              height: 40.r,
            ),
            Column(
              children: controller.state.list
                  .asMap()
                  .map(
                    (key, value) => MapEntry(
                      key,
                      MeCell(
                        icon: value.icon!,
                        title: value.name,
                        content: value.content,
                        onTap: value.onTap,
                      ),
                    ),
                  )
                  .values
                  .toList(),
            ),
          ],
        )
      ],
    );
  }

  @override
  Widget build(BuildContext context) {
    return GetBuilder<MeController>(
      builder: (_) {
        return Scaffold(
          backgroundColor: TopColors.main_color,
          body: SafeArea(
            child: _buildView(),
          ),
        );
      },
    );
  }
}
